﻿using System.Windows.Forms;
using WinForm.Modules;

namespace WinForm.Details
{
    public  partial class DetailBase : UserControl
    {
        protected ModuleBase ParentModuel { get; set; }

        protected DetailBase()
        {
            InitializeComponent();
        }

        protected DetailBase(ModuleBase praentModule)
        {
            InitializeComponent();
            ParentModuel = praentModule;
        }

        //todo 这个可以有
        public void UpdateActiveRibbonPageCaption()
        {
            //if (ActiveRibbonPage == null) return;
            //ActiveRibbonPage.Text = string.Format("{0}{1}", PageCaption, Dirty ? "*" : string.Empty);
            // 计算是否 Dirty 时，每一个edit控件都注册了valuechang事件
        }
        public void Save()
        {
            //BeforeModuleClose();
            //if (ValidateData())
            //{
            SaveData();
            ClearData();
            ParentModuel.RefreshData();//刷新
            //    Dirty = false;
            //    returnResult = DialogResult.Yes;
            //    return true;
            //}
                
        }
        public void SaveAndClose()
        {
            //if (Save())
            //{
            //    returnResult = DialogResult.OK;
            //    Close();
            //    return true;
            //}
            Save();
            Close();
            ParentModuel.RefreshData();//刷新
        }
        public void Close()
        {
            //BeforeModuleClose();
            //if (returnResult != DialogResult.OK)
            //{
            //    if (showCloseDialog && Dirty)
            //    {
            //        DialogResult result = XtraMessageBox.Show(this, ConstStrings.Get("CloseCancelFormWarning"), ConstStrings.Get("Warning"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            //        if (result == DialogResult.Cancel) return;
            //        if (result == DialogResult.Yes) Save();
            //    }
            //    else
            //    {
            //        CloseCancelForm();
            //    }
            //}
            //if (Session != null)
            //{
            //    this.editObject = SessionHelper.GetObject<VideoRentBaseObject>(this.editObject, externalSession());
            //    this.session.Dispose();
            //    this.session = null;
            //    SaveFormLayout();
            //    if (editObject != null) editObject.Reload();
            //}
            //Cursor.Current = Cursors.Default;
            //if (closeForm != null) closeForm(returnResult, editObject);
            Dispose();
            ParentModuel.ActiveDetailControl = null;
            ParentModuel.RaiseDetailChanged();
        }

        /// <summary>
        /// 保存数据，需要覆盖
        /// </summary>
        protected virtual void SaveData()
        {
        }

        /// <summary>
        /// 清空控件中的数据,需要覆盖
        /// </summary>
        protected virtual void ClearData()
        {
        }
    }
}
